/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tools;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;

/**
 *
 * eCOM - Adopte un Presta - Mars-Avril 2013
 * @author Kheira, Jef, William, Tuan-Long
 */
@Stateless
@LocalBean
public class EuroConverter implements IEuroConverter {

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")

    @Override
    public double convertToEuro(double amount, String currencySymbol) {

        double rate = getExchangeRate(currencySymbol);
        double result = amount / rate;

        int tmp = (int) Math.round(result * 100);

        return (tmp/100);
    }
    
    @Override
    public double convertFromEuro(double amount, String currencySymbol) {
        
        double rate = getExchangeRate(currencySymbol);
        double result = amount * rate;

        int tmp = (int) Math.round(result * 100);

        return (tmp/100);
        
    }
    
    @Override
    public String getCurrencyRealName(String currencySymbol) {
        Map<String,String> table = new HashMap<String, String>();

        table.put("EUR", "Euro");
        table.put("USD", "Dollar américain");
        table.put("GBP", "Livre britannique");

        String currency = table.get(currencySymbol);

        return currency;
    }
    
    @Override
    public double getExchangeRate(String currencySymbol) {
        Map<String,Double> table = new HashMap<String, Double>();

        table.put("EUR", new Double(1));
        table.put("USD", new Double(1.2974));
        table.put("GBP", new Double(0.8662));

        double currency = table.get(currencySymbol);

        return currency;
    }
    
    @Override
    public ArrayList<String> getCurrencySymbols() {
         ArrayList<String> listeCurrencySym = new ArrayList<String>();

        listeCurrencySym.add("EUR");
        listeCurrencySym.add("USD");
        listeCurrencySym.add("GBP");

        return listeCurrencySym;
    }
}
